<?php

namespace app\course\event\listeners\video\admin;

use app\course\logic\record\LearnRecord;
use app\course\model\record\LearnCourseRecord as Record;

class SectionDelete
{
    public static function handle($data)
    {
        $courseId  = $data['courseId'];
        $sectionId = $data['sectionId'];
        //** @var Record $recordMod */
        $recordMod  = app(Record::class);
        // 删除学习记录
        $recordMod->course($courseId)->whereSectionId($sectionId)->delete();
        //
        $users      = $recordMod->course($courseId)->column('user_id');
        $courseType = $recordMod->course($courseId)->value('course_type');
        foreach ($users as $userId) {
            app(LearnRecord::class)->calculateRate($courseId, $courseType, $userId);
        }
    }
}
